package com.mtons.mblog.modules.service.impl;

import com.mtons.mblog.base.lang.Consts;
import com.mtons.mblog.modules.entity.LearnPlan;
import com.mtons.mblog.modules.repository.LearnPlanRepository;
import com.mtons.mblog.modules.service.LearnPlanService;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * @author Tison
 */
@Service
public class LearnPlanServiceImpl implements LearnPlanService {

    @Resource
    private LearnPlanRepository rep;


    public LearnPlan save(LearnPlan obj) {
        return rep.save(obj);
    }


    @Transactional
    public List<LearnPlan> saveAll(Iterable<LearnPlan> list) {
        return rep.saveAll(list);
    }


    public LearnPlan getOne(String id) {
        return rep.getOne(id);
    }


    public LearnPlan findById(String id) {
        Optional<LearnPlan> obj = rep.findById(id);
        return obj.orElse(null);
    }


    public void deleteById(String id) {
        rep.deleteById(id);
    }


    @Transactional
    public void deleteAll(List list) {
        rep.deleteAll(list);
    }


    public void delete(LearnPlan obj) {
        rep.delete(obj);
    }


    public boolean existsById(String id) {
        return rep.existsById(id);
    }


    public long count() {
        return rep.count();
    }


    public List<LearnPlan> findAll() {
        return rep.findAll();
    }


    public List<LearnPlan> findAll(LearnPlan obj) {
        List<LearnPlan> list = rep.findAll(Example.of(obj));
        return list == null || list.size() < 1 ? null : list;
    }


    public List<LearnPlan> findAll(Sort sort) {
        return rep.findAll(sort);
    }


    public List<LearnPlan> findAllById(Iterable<String> ids) {
        return rep.findAllById(ids);
    }


    public List<LearnPlan> findAll(Example<LearnPlan> e) {
        return rep.findAll(e);
    }


    public List<LearnPlan> findAll(Example<LearnPlan> e, Sort sort) {
        return rep.findAll(e, sort);
    }


    public Page<LearnPlan> findAll(Pageable page) {
        return rep.findAll(page);
    }


    public Page<LearnPlan> findAll(Example<LearnPlan> e, Pageable page) {
        return rep.findAll(e, page);
    }


    public Page<LearnPlan> findAll(LearnPlan obj, Pageable page) {
        return rep.findAll(Example.of(obj), page);
    }


    @Transactional
    @Override
    public int updateEmailStatusById(String id) {
        return rep.updateEmailStatusById(Consts.COMMON_YES, id);
    }

    @Transactional
    @Override
    public int updateScoreById(String id, String score) {
        return rep.updateScoreById(id, score);
    }

    @Transactional
    @Override
    public int updateRemindStatusId(String id) {
        return rep.updateRemindStatusId(id);
    }
}
